﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Linq;
namespace Odyssey
{
    internal class StartupLoader
    {
        public static Type FindStartupType(string startupAssemblyName, string environmentName)
        {
            if (string.IsNullOrWhiteSpace(startupAssemblyName))
            {
                throw new ArgumentNullException("目标程序集不能为空.");
            }
            var assembly = Assembly.Load(new AssemblyName(startupAssemblyName));
            if (assembly == null)
            {
                throw new InvalidOperationException(String.Format("程序集“{0}”加载失败.", startupAssemblyName));
            }
            var typeOfIStartup = typeof(IStartup);
            var typeOfStartup = assembly.GetTypes().Where(x => typeOfIStartup.IsAssignableFrom(x));
            return typeOfStartup.First();
        }
    }
}
